﻿#include "ReMeshApp.h"

// TODO: Action自动创建，消除头文件
#include "AddBCAction.h"
#include "AddOutput.h"
#include "AddUserObject.h"
#include "CommandLine.h"
#include "CreateExecutioner.h"
#include "CreateMeshAction.h"
#include "CreateSystemAction.h"
#include "SetupDeviceAction.h"

#include "Executioner.h"

ReMeshApp::ReMeshApp(int argc, char** argv)
  : Application(argc, argv)
{
  _command_line = std::make_unique<CommandLine>(argc, argv);
}

void ReMeshApp::PrintLogo()
{
  std::string logo = R"(
Zaran
)";
  std::cout << logo << std::endl;
}
void ReMeshApp::Run()
{
  PrintLogo();
  ParseCLI();
  CreateActions();
  SetupDevice();

  RunExecutioner();
}

void ReMeshApp::RunExecutioner()
{
  _executioner->Init();
  _executioner->Execute();
}

void ReMeshApp::CreateActions()
{
  _ifile = _command_line->GetValue<std::string>("-i");
  //_ifile = "isovortex.i";
  _parser = std::make_shared<Parser>(_ifile);

  _awh.push_back(std::make_shared<SetupDeviceAction>(*this));
  _awh.push_back(std::make_shared<CreateMeshAction>(*this));
  _awh.push_back(std::make_shared<CreateSystemAction>(*this));
  _awh.push_back(std::make_shared<AddBCAction>(*this));
  _awh.push_back(std::make_shared<CreateExecutioner>(*this));
  _awh.push_back(std::make_shared<AddOutputAction>(*this));
  _awh.push_back(std::make_shared<AddUserObjectAction>(*this));

  for (auto& action : _awh)
  {
    action->Execute();
  }
}
